home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Learn Microsoft Visual Basic 6.0 Now
/
Learn Microsoft Visual Basic 6.0 Now (Microsoft Press)(X03-58607)(1998).ISO
/
media
/
chap05
/
b05d005.cc2
< prev
next >
Wrap
Text File
|
1998-06-07
|
2KB
|
54 lines
0, The If...Then decision structure is a
3, useful tool for adding program logic to
5, your application. In this demonstration
8, you'll use an If...Then decision structure
10, to validate users as they log into a
12, program. With a little creativity, you can
16, use this technique to password protect
18, a network application or a stand-alone
20, program that you want to protect from
22, wandering eyes. First, I'll create a
24, command button object on my form and give it
27, the name LogIn. I'll enter the caption,
33, LogIn, in the Properties window. Then,
40, I'll shrink a few of my programming tools
43, to make room for the Code window. I want
45, to be able to see all the program code
47, that I'm going to write. Next, I'll open
51, the Command1_Click event procedure and
55, use it now to create an If...Then
57, decision structure that recognizes the users,
59, Laura and Mark. Typing the program code
63, will take just a few moments. This event
75, procedure uses an InputBox function to
78, prompt the user for their name and
80, stores the name in the UserName variable. The
85, event procedure then prompts the user
86, for a login password and stores the
89, password in the Pass variable. An If...Then
93, decision structure then checks to see if
95, the user name and password were either
98, Laura and May 17th, or Mark and trek. If
102, either conditional expression evaluates
104, to True, a message box is displayed
106, welcoming the validated user to the program.
110, If either the user name or password does
111, not match, the message "Sorry, I don't
116, recognize you," is displayed on the
117, screen. The program is then terminated with
120, the Visual Basic End statement. The
124, keywords in this decision structure are If,
127, which tests a condition, Else If, which
131, tests a second condition, and Else,
135, which picks up the pieces if none of the
136, conditional tests evaluates to True. Now,
140, I'll run the program. When I click the
149, Login button, two dialog boxes appear that
152, prompted me for my name and my
154, password. If I type a recognizable pair, I'm
161, welcomed to the system. However, if I try
165, again and type a pair that is not
166, recognizable, I receive the message, "Sorry, I
176, don't recognize you," and the program
179, ends. Now, what was my password, anyway?
183, END